package repository.repo;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import repository.ConnectionProvider;

/**
 * User: nickname password
 */
public class UserRepo {
    public boolean register(String nickname, String password) {
        try {
            Connection con = ConnectionProvider.getConnection();
            Statement stm = con.createStatement();
            String sql_insert = "insert into user(nickname,password)values('" + nickname + "','" + password + "')";
            return stm.execute(sql_insert);
        } catch (SQLException e) {
            System.out.println("SQL Exception: " + e);
            return false;
        }
    }

    public boolean login(String username, String password) {
        try {
            Connection con = ConnectionProvider.getConnection();
            Statement stm = con.createStatement();
            String sql = "select * from user where nickname ='" + username + "'" + "and password = '" + password + "'";
            ResultSet rs = stm.executeQuery(sql);
            ConnectionProvider.closeConnection(stm, con);
            return rs.next();
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }
}
